﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


using MegaSportsStore.Domain.MegaAbstract;
using MegaSportsStore.Domain.MegaEntities;

namespace MegaSportsStore.WebUI.Controllers
{
    public class MegaProductController : Controller
    {
        private IMegaProductRepository repository;

        public int PageSize = 2;
        public MegaProductController(IMegaProductRepository productRepository)
        {
            repository = productRepository;
        }

        //
        // GET: /MegaProduct/

        public ViewResult List(int page = 1)
        {
            if (page >= 1)
            {
                var prodList = repository.MegaProducts
                .OrderBy(p => p.Id)
                .Skip((page - 1) * PageSize)
                .Take(PageSize);

                if (prodList.Count() > 0)
                {
                    return View(prodList);
                }
            }
            ViewBag.Message = "No products to display!!";
            return View();
        }

    }
}
